package main

import (
	"MBTIx/middleware"
	"MBTIx/routers"
	"log"

	"github.com/gin-gonic/gin"
	"github.com/jmoiron/sqlx"
	_ "github.com/lib/pq"
)

func init_routers(server *gin.Engine){
	auth := middleware.JWTAuthMiddleware()
	routers.Auth_router(server,auth)
	routers.Student_router(server,auth)
	routers.College_router(server,auth)
	routers.Dep_router(server,auth)
	routers.Class_router(server,auth)
	routers.Pro_router(server,auth)
	routers.Mold_router(server,auth)
	routers.Per_router(server,auth)
	routers.Test_router(server,auth)
}

func main() {
	db, err := sqlx.Connect("postgres", "user=postgres dbname=MBTI password=fyh163617 sslmode=disable")
	if err != nil {
		log.Fatalln(err)
	}

	server := gin.Default()
	server.Use(middleware.StateContext(db))
	init_routers(server)
	
	server.Run(":8080")
}
